package com.wiscamp.ninechapters.challenges.infrastructure.mappers;

import com.wiscamp.ninechapters.challenges.infrastructure.po.MedalPO;
import com.wiscamp.ninechapters.challenges.infrastructure.po.UserMedalPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;

@Repository
public interface UserMedalMapper extends JpaRepository<UserMedalPO, Long>, JpaSpecificationExecutor<UserMedalPO> {

    /**
     * 通过用户编号获取所获得的成就勋章列表
     *
     * @param userId
     * @return
     */

    @Query(value = "select m from MedalPO m, UserMedalPO e where m.medalId = e.medalId and m.deleted = false and e.userId = :userId")
    Collection<MedalPO> getUserMedals(long userId);
}